package fr.inria.phoenix.scenario.bwsnfirefighting.impl.controller;

import fr.inria.diagen.core.ServiceConfiguration;
import fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.DangerLevel;
import fr.inria.phoenix.scenario.bwsnfirefighting.framework.distributed.alarmmanager.AlarmManager;
import fr.inria.phoenix.scenario.bwsnfirefighting.framework.distributed.alarmmanager.LightComposite;
import fr.inria.phoenix.scenario.bwsnfirefighting.framework.distributed.alarmmanager.SoundComposite;

public class AlarmManagerImpl extends AlarmManager {
	
	DangerLevel previousState = DangerLevel.SAFE;

	public AlarmManagerImpl(ServiceConfiguration serviceConfiguration) {
		super(serviceConfiguration);
	}

	@Override
	public void onNewBuildingAlertDetection(
			DangerLevel newBuildingAlertDetectionValue) {
		LightComposite lights = this.allLights();
		SoundComposite sounds = this.allSounds();
		if (newBuildingAlertDetectionValue == DangerLevel.ALERT){
			lights.activate();
			sounds.activate();
			previousState = DangerLevel.ALERT;
		}
		else if(newBuildingAlertDetectionValue == DangerLevel.WARNING){
			if (previousState == DangerLevel.ALERT){
				lights.activate();
				sounds.activate();
			}
			else {
				lights.deactivate();
				sounds.deactivate();
			}
			previousState = DangerLevel.WARNING;
		}
		else {
			lights.deactivate();
			sounds.deactivate();
			previousState = DangerLevel.SAFE;
		}
		
	}

}
